<?php
$_SESSION['steps'][$_GET['action']] = false;
if($_SESSION['index']=='')
{
	displayError('Une erreur interne s\'est produit (perte du fichier index.xml)');
}
$setup = new SimpleXMLElement($_SESSION['index']);
$list = array();
$one_error = false;
foreach ($setup->screens[0]->requirement as $requirement)
{
	$type = ''.$requirement['type'];
	$name = ''.$requirement['name'];
	$min_version = ''.$requirement['minversion'];
	$max_version = ''.$requirement['maxnversion'];
	switch($type)
	{
		case 'engine':
			switch($name)
			{
				case 'php':
					$support = true;
					$version = phpversion();
					break;
			}
			break;
		case 'sgdb':
			switch($name)
			{
				case 'mysql':
					$support = function_exists( 'mysql_connect' );
					ob_start();
					phpinfo();
					$php = ob_get_contents();
					ob_end_clean();
					preg_match('/Client API version[^0-9]*([0-9].[0-9].[0-9])/', $php, $match);
					$version = $match[1];//temps qu'on est pas connecté, impossible de connaitre la version de mysql...
					break;
			}
			break;
		case 'phpext':
			$support = extension_loaded($name);
			$name = 'php_'.$name.'.dll';
			$version='';
			break;
		case 'phpfunc':
			$support = function_exists(''.$requirement['function']);
			$name = $name.'()';
			$version='';
			break;
		case 'package':
			$version = '0.0.0.0';
			if(file_exists($current_path.'/install_report.php5'))
			{
				include($current_path.'/install_report.php5');
				$version = $install_report['application_version'];
			}
			$support = true;
			$name = INSTALL_APPLICATION_NAME;
			break;
	}
	$ok = $support;
	if($ok)
	{
		if($min_version!='')
		{
			if($version=='')
			{
				$ok= false;
			}
			elseif(compareVersions($version, $min_version)<0)
			{
				$ok = false;
			}
		}
	}
	if($ok)
	{
		if($max_version!='')
		{
			if($version=='')
			{
				$ok= false;
			}
			elseif(compareVersions($version, $max_version)>0)
			{
				$ok = false;
			}
		}
	}
	if($min_version!='')
	{
		$need = '<b>'.$name.' : </b>'.$min_version;
	}
	else
	{
		$need = '<b>'.$name.'</b>';
	}

	if($ok)
	{
		$list[] = '<tr class="install_message_ok"><td>'.$need.'</td><td>&nbsp;&nbsp;[OK]</td></tr>';
	}
	else
	{
		$one_error = true;
		$list[] = '<tr class="install_message_error"><td>'.$need.'</td><td>&nbsp;&nbsp;[Error]</td></tr>';
	}
}
?>
document.getElementById('install_content_intro').innerHTML = 'Pour être installé et/ou utilisé, la présence sur le server de certaines librairies/programme est nécéssaire.';
document.getElementById('install_content_data').innerHTML = '<h3>Système Requis :</h3><br><table cellpadding="0" cellspacing="0"><?php echo strToJs(implode('', $list))?></table>';
<?php
	if($one_error)
	{
		$_SESSION['steps'][$_GET['action']] = false;
?>
document.getElementById('install_next').style.display='none'
document.getElementById('install_back').style.display='none'
<?php
	}
	else 
	{
		$_SESSION['steps'][$_GET['action']] = true;
		displayButtons();
	}
?>